$(function () {

    //获取统计数据
    $.ajax({
        type: 'get',
        url: BigNew.data_info,
        success(backData) {
            $('.scolor01').children('em').html(backData.totalArticle);
            $('.scolor02').children('em').html(backData.dayArticle);
            $('.scolor03').children('em').html(backData.totalComment);
            $('.scolor04').children('em').html(backData.dayComment);
        }
    });

    //日新增文章数量统计
    $.ajax({
        type: 'get',
        url: BigNew.data_article,
        success(backData) {
            // 折线图 
            let obj = backData;
            loadEchars(obj);
            function loadEchars(obj) {
                // 基于准备好的dom，初始化echarts实例
                let myChart = echarts.init(document.getElementById('curve_show'));

                let data = [];
                let date = [];
                for (let i = 0; i < obj.date.length; i++) {
                    data.push(obj.date[i].count);
                    date.push(obj.date[i].date);
                }

                option = {
                    tooltip: {
                        trigger: 'axis',
                        position: function (pt) {
                            return [pt[0], '10%'];
                        }
                    },
                    title: {
                        left: 'center',
                        text: '月新增文章数',
                    },

                    xAxis: {
                        name: '日',
                        type: 'category',
                        boundaryGap: false,
                        data: date
                    },
                    legend: {
                        data: ['新增文章'],
                        top: '40'
                    },
                    toolbox: {
                        show: true,
                        feature: {
                            dataZoom: {
                                yAxisIndex: 'none'
                            },
                            dataView: { readOnly: false },
                            magicType: { type: ['line', 'bar'] },
                            restore: {},
                            saveAsImage: {}
                        },
                        right: 50
                    },
                    yAxis: {
                        type: 'value',
                        boundaryGap: [0, '100%']
                    },
                    series: [
                        {
                            name: '新增文章',
                            type: 'line',
                            smooth: true,
                            // symbol: 'none',
                            sampling: 'average',
                            itemStyle: {
                                color: '#f80'
                            },
                            areaStyle: {
                                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                                    offset: 0,
                                    color: 'rgba(255,136,0,0.39)'
                                }, {
                                    offset: .34,
                                    color: 'rgba(255,180,0,0.25)'
                                },
                                {
                                    offset: 1,
                                    color: 'rgba(255,222,0,0.00)'
                                }])
                            },
                            data: data
                        }
                    ],
                }
                // 使用刚指定的配置项和数据显示图表。
                myChart.setOption(option);
            }
        },
    });

    // 图表颜色
    let color = ['#5885e8', '#13cfd5', '#00ce68', '#ff9565', '#20ff19', '#ff5500'];
    //各类型文章数量统计
    let arrName = [];
    let arr = [];
    $.ajax({
        type: 'get',
        url: BigNew.data_category,
        success(backData) {

            for (let i = 0; i < backData.date.length; i++) {
                arrName.push(backData.date[i].name);
                arr.push({
                    value: backData.date[i].articles,
                    name: backData.date[i].name
                });
            };
            // 环形图
            // 基于准备好的dom，初始化echarts实例
            let myChart1 = echarts.init(document.getElementById('pie_show'));

            option1 = {

                title: {
                    left: 'center',
                    text: '分类文章数量比',
                },

                tooltip: {
                    trigger: 'item',
                    formatter: "{a} <br/>{b}: {c} ({d}%)"
                },
                legend: {
                    orient: 'horizontal',
                    x: 'center',
                    data: arrName,
                    top: 30
                },
                color: color,
                series: [
                    {
                        name: '分类名称',
                        type: 'pie',
                        center: ['50%', '60%'],
                        radius: ['50%', '70%'],
                        avoidLabelOverlap: false,
                        label: {
                            emphasis: {
                                show: true,
                                textStyle: {
                                    fontSize: '30',
                                    fontWeight: 'bold'
                                }
                            }
                        },
                        data: arr


                    }
                ]
            };
            // 使用刚指定的配置项和数据显示图表。
            myChart1.setOption(option1);


        },
    });

    //日文章访问量

    $.ajax({
        type: 'get',
        url: BigNew.data_visit,
        success(backData) {
            console.log(backData);
            let series = [];
            let data = [];
            let date = [];
            for (let key in backData.data) {
                date.push(key)
                data.push(backData.data[key]);
            }
            for (let i = 0; i < arrName.length; i++) {
                series.push({
                    name: arrName[i],
                    type: 'bar',
                    data: data
                })
            }
            console.log(data);
            console.log(arrName);
            console.log(series);
            // 柱状图 
            // 基于准备好的dom，初始化echarts实例
            let myChart2 = echarts.init(document.getElementById('column_show'));

            option2 = {
                title: {
                    left: 'center',
                    text: '分类访问量',
                },
                tooltip: {
                    trigger: 'axis',
                    axisPointer: {
                        // 坐标轴指示器，坐标轴触发有效
                        type: 'line', // 默认为直线，可选为：'line' | 'shadow'
                    },
                },
                legend: {
                    data: arrName,
                    top: 30,
                },
                grid: {
                    left: '3%',
                    right: '4%',
                    bottom: '3%',
                    containLabel: true,
                },
                xAxis: [
                    {
                        type: 'category',
                        data: date,
                    },
                ],
                yAxis: [
                    {
                        type: 'value',
                    },
                ],
                color: color,
                series: series,
            }

            // 使用刚指定的配置项和数据显示图表。
            myChart2.setOption(option2);

        },



    });







});